﻿using DataWorks_Sqlite.MappingClass;
using DataWorks_Tools.BasicMethods;
using DataWorks_Tools.CleanDetails;
using DataWorks_Tools.MappModals;
using DataWorks_Tools.SpikeDetails;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataWorks_Tools.ProcessExcute.Spike
{
    public class SpikeProcess
    {
        public static async Task<List<string>> SpikeProcessExcute(dw_props_admin dw_Props_Admin, dw_props_spikeremove dw_Props_Spikeremove)
        {
            var selectdatefilearray = dw_Props_Spikeremove.selecteddirectory.ReComma().Split(',');
            var spike_meanpoints = dw_Props_Admin.spike_meanpoints;
            var spike_vairancepoints = dw_Props_Admin.spike_vairancepoints;
            var spike_threadspercentage = dw_Props_Admin.spike_threadspercentage;
            var spike_ratio = dw_Props_Admin.spike_ratio;
            var originaldatapath = dw_Props_Spikeremove.originaldatapath.YXHPathReplace(); ;
            var savedatapath = dw_Props_Spikeremove.savedatapath.YXHPathReplace(); ;
            var spikeidx = dw_Props_Spikeremove.spikechanidx.ReComma().Split(',');
            var combinedpath = dw_Props_Spikeremove.combinedpath.YXHPathReplace();
            var ismultithreads = dw_Props_Admin.ismultithreads;

            var row = new SpikeModal();
            row.pointcounts = dw_Props_Admin.continuouscount;
            row.odpath = originaldatapath;
            row.rdpath = savedatapath;
            row.datedir = selectdatefilearray;
            row.ratio = spike_ratio;
            row.meanpoints = spike_meanpoints;
            row.vairancepoints = spike_vairancepoints;
            row.threadspercentage = spike_threadspercentage;
            row.spikeidx=SpikeDetailsMethods.YXHGetSpikeIdx(spikeidx);
            row.referdir = combinedpath;
            if (originaldatapath != null && savedatapath != null && selectdatefilearray != null && row.spikeidx.Count > 0)
            {
                if(ismultithreads == 1)
                {
                    var t = await SpikeDetailsMethods.YXHExcuteSpikeMultiThreadsAsync(row);
                    return t;
                }
                else
                {
                    var t = await SpikeDetailsMethods.YXHExcuteSpikeMultiThreadsAsync(row);
                    return t;
                }
            }
            else
            {
                return new List<string>() { "spike参数错误" };
            }
        }
    }
}
